package com.atguigu.search.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by 13 on 2017/5/5.
 */
public class ThreadPoolDemo {
  public static class MyTask implements Runnable {

    @Override
    public void run() {
      System.out.println(System.currentTimeMillis() + "Thread ID:" + Thread.currentThread().getId());

      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
  }


  public static void main(String args[]) {
    MyTask myTask = new MyTask();
//        ExecutorService executorService = Executors.newFixedThreadPool(5);
//        ExecutorService executorService = Executors.newCachedThreadPool();
    ExecutorService executorService = Executors.newSingleThreadExecutor();
    for (int i = 0; i < 20; i++) {
      executorService.submit(myTask);
    }
  }
}
